
_zombie:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include "stat.h"
#include "user.h"

int
main(void)
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 10             	sub    $0x10,%esp
  if(fork() > 0)
   9:	e8 76 02 00 00       	call   284 <fork>
   e:	85 c0                	test   %eax,%eax
  10:	7e 0c                	jle    1e <main+0x1e>
    sleep(5);  // Let child exit before parent.
  12:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
  19:	e8 fe 02 00 00       	call   31c <sleep>
  exit();
  1e:	e8 69 02 00 00       	call   28c <exit>
  23:	90                   	nop

00000024 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
  24:	55                   	push   %ebp
  25:	89 e5                	mov    %esp,%ebp
  27:	57                   	push   %edi
  28:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
  29:	8b 4d 08             	mov    0x8(%ebp),%ecx
  2c:	8b 55 10             	mov    0x10(%ebp),%edx
  2f:	8b 45 0c             	mov    0xc(%ebp),%eax
  32:	89 cb                	mov    %ecx,%ebx
  34:	89 df                	mov    %ebx,%edi
  36:	89 d1                	mov    %edx,%ecx
  38:	fc                   	cld    
  39:	f3 aa                	rep stos %al,%es:(%edi)
  3b:	89 ca                	mov    %ecx,%edx
  3d:	89 fb                	mov    %edi,%ebx
  3f:	89 5d 08             	mov    %ebx,0x8(%ebp)
  42:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
  45:	5b                   	pop    %ebx
  46:	5f                   	pop    %edi
  47:	5d                   	pop    %ebp
  48:	c3                   	ret    

00000049 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
  49:	55                   	push   %ebp
  4a:	89 e5                	mov    %esp,%ebp
  4c:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
  4f:	8b 45 08             	mov    0x8(%ebp),%eax
  52:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
  55:	90                   	nop
  56:	8b 45 0c             	mov    0xc(%ebp),%eax
  59:	0f b6 10             	movzbl (%eax),%edx
  5c:	8b 45 08             	mov    0x8(%ebp),%eax
  5f:	88 10                	mov    %dl,(%eax)
  61:	8b 45 08             	mov    0x8(%ebp),%eax
  64:	0f b6 00             	movzbl (%eax),%eax
  67:	84 c0                	test   %al,%al
  69:	0f 95 c0             	setne  %al
  6c:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  70:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
  74:	84 c0                	test   %al,%al
  76:	75 de                	jne    56 <strcpy+0xd>
    ;
  return os;
  78:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  7b:	c9                   	leave  
  7c:	c3                   	ret    

0000007d <strcmp>:

int
strcmp(const char *p, const char *q)
{
  7d:	55                   	push   %ebp
  7e:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
  80:	eb 08                	jmp    8a <strcmp+0xd>
    p++, q++;
  82:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  86:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
  8a:	8b 45 08             	mov    0x8(%ebp),%eax
  8d:	0f b6 00             	movzbl (%eax),%eax
  90:	84 c0                	test   %al,%al
  92:	74 10                	je     a4 <strcmp+0x27>
  94:	8b 45 08             	mov    0x8(%ebp),%eax
  97:	0f b6 10             	movzbl (%eax),%edx
  9a:	8b 45 0c             	mov    0xc(%ebp),%eax
  9d:	0f b6 00             	movzbl (%eax),%eax
  a0:	38 c2                	cmp    %al,%dl
  a2:	74 de                	je     82 <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
  a4:	8b 45 08             	mov    0x8(%ebp),%eax
  a7:	0f b6 00             	movzbl (%eax),%eax
  aa:	0f b6 d0             	movzbl %al,%edx
  ad:	8b 45 0c             	mov    0xc(%ebp),%eax
  b0:	0f b6 00             	movzbl (%eax),%eax
  b3:	0f b6 c0             	movzbl %al,%eax
  b6:	89 d1                	mov    %edx,%ecx
  b8:	29 c1                	sub    %eax,%ecx
  ba:	89 c8                	mov    %ecx,%eax
}
  bc:	5d                   	pop    %ebp
  bd:	c3                   	ret    

000000be <strlen>:

uint
strlen(char *s)
{
  be:	55                   	push   %ebp
  bf:	89 e5                	mov    %esp,%ebp
  c1:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
  c4:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  cb:	eb 04                	jmp    d1 <strlen+0x13>
  cd:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
  d1:	8b 55 fc             	mov    -0x4(%ebp),%edx
  d4:	8b 45 08             	mov    0x8(%ebp),%eax
  d7:	01 d0                	add    %edx,%eax
  d9:	0f b6 00             	movzbl (%eax),%eax
  dc:	84 c0                	test   %al,%al
  de:	75 ed                	jne    cd <strlen+0xf>
    ;
  return n;
  e0:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  e3:	c9                   	leave  
  e4:	c3                   	ret    

000000e5 <memset>:

void*
memset(void *dst, int c, uint n)
{
  e5:	55                   	push   %ebp
  e6:	89 e5                	mov    %esp,%ebp
  e8:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
  eb:	8b 45 10             	mov    0x10(%ebp),%eax
  ee:	89 44 24 08          	mov    %eax,0x8(%esp)
  f2:	8b 45 0c             	mov    0xc(%ebp),%eax
  f5:	89 44 24 04          	mov    %eax,0x4(%esp)
  f9:	8b 45 08             	mov    0x8(%ebp),%eax
  fc:	89 04 24             	mov    %eax,(%esp)
  ff:	e8 20 ff ff ff       	call   24 <stosb>
  return dst;
 104:	8b 45 08             	mov    0x8(%ebp),%eax
}
 107:	c9                   	leave  
 108:	c3                   	ret    

00000109 <strchr>:

char*
strchr(const char *s, char c)
{
 109:	55                   	push   %ebp
 10a:	89 e5                	mov    %esp,%ebp
 10c:	83 ec 04             	sub    $0x4,%esp
 10f:	8b 45 0c             	mov    0xc(%ebp),%eax
 112:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 115:	eb 14                	jmp    12b <strchr+0x22>
    if(*s == c)
 117:	8b 45 08             	mov    0x8(%ebp),%eax
 11a:	0f b6 00             	movzbl (%eax),%eax
 11d:	3a 45 fc             	cmp    -0x4(%ebp),%al
 120:	75 05                	jne    127 <strchr+0x1e>
      return (char*)s;
 122:	8b 45 08             	mov    0x8(%ebp),%eax
 125:	eb 13                	jmp    13a <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 127:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 12b:	8b 45 08             	mov    0x8(%ebp),%eax
 12e:	0f b6 00             	movzbl (%eax),%eax
 131:	84 c0                	test   %al,%al
 133:	75 e2                	jne    117 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 135:	b8 00 00 00 00       	mov    $0x0,%eax
}
 13a:	c9                   	leave  
 13b:	c3                   	ret    

0000013c <gets>:

char*
gets(char *buf, int max)
{
 13c:	55                   	push   %ebp
 13d:	89 e5                	mov    %esp,%ebp
 13f:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 142:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 149:	eb 46                	jmp    191 <gets+0x55>
    cc = read(0, &c, 1);
 14b:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 152:	00 
 153:	8d 45 ef             	lea    -0x11(%ebp),%eax
 156:	89 44 24 04          	mov    %eax,0x4(%esp)
 15a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 161:	e8 3e 01 00 00       	call   2a4 <read>
 166:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 169:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 16d:	7e 2f                	jle    19e <gets+0x62>
      break;
    buf[i++] = c;
 16f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 172:	8b 45 08             	mov    0x8(%ebp),%eax
 175:	01 c2                	add    %eax,%edx
 177:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 17b:	88 02                	mov    %al,(%edx)
 17d:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 181:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 185:	3c 0a                	cmp    $0xa,%al
 187:	74 16                	je     19f <gets+0x63>
 189:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 18d:	3c 0d                	cmp    $0xd,%al
 18f:	74 0e                	je     19f <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 191:	8b 45 f4             	mov    -0xc(%ebp),%eax
 194:	83 c0 01             	add    $0x1,%eax
 197:	3b 45 0c             	cmp    0xc(%ebp),%eax
 19a:	7c af                	jl     14b <gets+0xf>
 19c:	eb 01                	jmp    19f <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 19e:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 19f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1a2:	8b 45 08             	mov    0x8(%ebp),%eax
 1a5:	01 d0                	add    %edx,%eax
 1a7:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 1aa:	8b 45 08             	mov    0x8(%ebp),%eax
}
 1ad:	c9                   	leave  
 1ae:	c3                   	ret    

000001af <stat>:

int
stat(char *n, struct stat *st)
{
 1af:	55                   	push   %ebp
 1b0:	89 e5                	mov    %esp,%ebp
 1b2:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 1b5:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 1bc:	00 
 1bd:	8b 45 08             	mov    0x8(%ebp),%eax
 1c0:	89 04 24             	mov    %eax,(%esp)
 1c3:	e8 04 01 00 00       	call   2cc <open>
 1c8:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 1cb:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 1cf:	79 07                	jns    1d8 <stat+0x29>
    return -1;
 1d1:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 1d6:	eb 23                	jmp    1fb <stat+0x4c>
  r = fstat(fd, st);
 1d8:	8b 45 0c             	mov    0xc(%ebp),%eax
 1db:	89 44 24 04          	mov    %eax,0x4(%esp)
 1df:	8b 45 f4             	mov    -0xc(%ebp),%eax
 1e2:	89 04 24             	mov    %eax,(%esp)
 1e5:	e8 fa 00 00 00       	call   2e4 <fstat>
 1ea:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 1ed:	8b 45 f4             	mov    -0xc(%ebp),%eax
 1f0:	89 04 24             	mov    %eax,(%esp)
 1f3:	e8 bc 00 00 00       	call   2b4 <close>
  return r;
 1f8:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 1fb:	c9                   	leave  
 1fc:	c3                   	ret    

000001fd <atoi>:

int
atoi(const char *s)
{
 1fd:	55                   	push   %ebp
 1fe:	89 e5                	mov    %esp,%ebp
 200:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 203:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 20a:	eb 23                	jmp    22f <atoi+0x32>
    n = n*10 + *s++ - '0';
 20c:	8b 55 fc             	mov    -0x4(%ebp),%edx
 20f:	89 d0                	mov    %edx,%eax
 211:	c1 e0 02             	shl    $0x2,%eax
 214:	01 d0                	add    %edx,%eax
 216:	01 c0                	add    %eax,%eax
 218:	89 c2                	mov    %eax,%edx
 21a:	8b 45 08             	mov    0x8(%ebp),%eax
 21d:	0f b6 00             	movzbl (%eax),%eax
 220:	0f be c0             	movsbl %al,%eax
 223:	01 d0                	add    %edx,%eax
 225:	83 e8 30             	sub    $0x30,%eax
 228:	89 45 fc             	mov    %eax,-0x4(%ebp)
 22b:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 22f:	8b 45 08             	mov    0x8(%ebp),%eax
 232:	0f b6 00             	movzbl (%eax),%eax
 235:	3c 2f                	cmp    $0x2f,%al
 237:	7e 0a                	jle    243 <atoi+0x46>
 239:	8b 45 08             	mov    0x8(%ebp),%eax
 23c:	0f b6 00             	movzbl (%eax),%eax
 23f:	3c 39                	cmp    $0x39,%al
 241:	7e c9                	jle    20c <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 243:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 246:	c9                   	leave  
 247:	c3                   	ret    

00000248 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 248:	55                   	push   %ebp
 249:	89 e5                	mov    %esp,%ebp
 24b:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 24e:	8b 45 08             	mov    0x8(%ebp),%eax
 251:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 254:	8b 45 0c             	mov    0xc(%ebp),%eax
 257:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 25a:	eb 13                	jmp    26f <memmove+0x27>
    *dst++ = *src++;
 25c:	8b 45 f8             	mov    -0x8(%ebp),%eax
 25f:	0f b6 10             	movzbl (%eax),%edx
 262:	8b 45 fc             	mov    -0x4(%ebp),%eax
 265:	88 10                	mov    %dl,(%eax)
 267:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 26b:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 26f:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 273:	0f 9f c0             	setg   %al
 276:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 27a:	84 c0                	test   %al,%al
 27c:	75 de                	jne    25c <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 27e:	8b 45 08             	mov    0x8(%ebp),%eax
}
 281:	c9                   	leave  
 282:	c3                   	ret    
 283:	90                   	nop

00000284 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 284:	b8 01 00 00 00       	mov    $0x1,%eax
 289:	cd 40                	int    $0x40
 28b:	c3                   	ret    

0000028c <exit>:
SYSCALL(exit)
 28c:	b8 02 00 00 00       	mov    $0x2,%eax
 291:	cd 40                	int    $0x40
 293:	c3                   	ret    

00000294 <wait>:
SYSCALL(wait)
 294:	b8 03 00 00 00       	mov    $0x3,%eax
 299:	cd 40                	int    $0x40
 29b:	c3                   	ret    

0000029c <pipe>:
SYSCALL(pipe)
 29c:	b8 04 00 00 00       	mov    $0x4,%eax
 2a1:	cd 40                	int    $0x40
 2a3:	c3                   	ret    

000002a4 <read>:
SYSCALL(read)
 2a4:	b8 05 00 00 00       	mov    $0x5,%eax
 2a9:	cd 40                	int    $0x40
 2ab:	c3                   	ret    

000002ac <write>:
SYSCALL(write)
 2ac:	b8 10 00 00 00       	mov    $0x10,%eax
 2b1:	cd 40                	int    $0x40
 2b3:	c3                   	ret    

000002b4 <close>:
SYSCALL(close)
 2b4:	b8 15 00 00 00       	mov    $0x15,%eax
 2b9:	cd 40                	int    $0x40
 2bb:	c3                   	ret    

000002bc <kill>:
SYSCALL(kill)
 2bc:	b8 06 00 00 00       	mov    $0x6,%eax
 2c1:	cd 40                	int    $0x40
 2c3:	c3                   	ret    

000002c4 <exec>:
SYSCALL(exec)
 2c4:	b8 07 00 00 00       	mov    $0x7,%eax
 2c9:	cd 40                	int    $0x40
 2cb:	c3                   	ret    

000002cc <open>:
SYSCALL(open)
 2cc:	b8 0f 00 00 00       	mov    $0xf,%eax
 2d1:	cd 40                	int    $0x40
 2d3:	c3                   	ret    

000002d4 <mknod>:
SYSCALL(mknod)
 2d4:	b8 11 00 00 00       	mov    $0x11,%eax
 2d9:	cd 40                	int    $0x40
 2db:	c3                   	ret    

000002dc <unlink>:
SYSCALL(unlink)
 2dc:	b8 12 00 00 00       	mov    $0x12,%eax
 2e1:	cd 40                	int    $0x40
 2e3:	c3                   	ret    

000002e4 <fstat>:
SYSCALL(fstat)
 2e4:	b8 08 00 00 00       	mov    $0x8,%eax
 2e9:	cd 40                	int    $0x40
 2eb:	c3                   	ret    

000002ec <link>:
SYSCALL(link)
 2ec:	b8 13 00 00 00       	mov    $0x13,%eax
 2f1:	cd 40                	int    $0x40
 2f3:	c3                   	ret    

000002f4 <mkdir>:
SYSCALL(mkdir)
 2f4:	b8 14 00 00 00       	mov    $0x14,%eax
 2f9:	cd 40                	int    $0x40
 2fb:	c3                   	ret    

000002fc <chdir>:
SYSCALL(chdir)
 2fc:	b8 09 00 00 00       	mov    $0x9,%eax
 301:	cd 40                	int    $0x40
 303:	c3                   	ret    

00000304 <dup>:
SYSCALL(dup)
 304:	b8 0a 00 00 00       	mov    $0xa,%eax
 309:	cd 40                	int    $0x40
 30b:	c3                   	ret    

0000030c <getpid>:
SYSCALL(getpid)
 30c:	b8 0b 00 00 00       	mov    $0xb,%eax
 311:	cd 40                	int    $0x40
 313:	c3                   	ret    

00000314 <sbrk>:
SYSCALL(sbrk)
 314:	b8 0c 00 00 00       	mov    $0xc,%eax
 319:	cd 40                	int    $0x40
 31b:	c3                   	ret    

0000031c <sleep>:
SYSCALL(sleep)
 31c:	b8 0d 00 00 00       	mov    $0xd,%eax
 321:	cd 40                	int    $0x40
 323:	c3                   	ret    

00000324 <uptime>:
SYSCALL(uptime)
 324:	b8 0e 00 00 00       	mov    $0xe,%eax
 329:	cd 40                	int    $0x40
 32b:	c3                   	ret    

0000032c <signal>:

//our addition
SYSCALL(signal)
 32c:	b8 1f 00 00 00       	mov    $0x1f,%eax
 331:	cd 40                	int    $0x40
 333:	c3                   	ret    

00000334 <sigsend>:
SYSCALL(sigsend)
 334:	b8 20 00 00 00       	mov    $0x20,%eax
 339:	cd 40                	int    $0x40
 33b:	c3                   	ret    

0000033c <alarm>:
SYSCALL(alarm)
 33c:	b8 21 00 00 00       	mov    $0x21,%eax
 341:	cd 40                	int    $0x40
 343:	c3                   	ret    

00000344 <getTicks>:
SYSCALL(getTicks)
 344:	b8 22 00 00 00       	mov    $0x22,%eax
 349:	cd 40                	int    $0x40
 34b:	c3                   	ret    

0000034c <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 34c:	55                   	push   %ebp
 34d:	89 e5                	mov    %esp,%ebp
 34f:	83 ec 28             	sub    $0x28,%esp
 352:	8b 45 0c             	mov    0xc(%ebp),%eax
 355:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 358:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 35f:	00 
 360:	8d 45 f4             	lea    -0xc(%ebp),%eax
 363:	89 44 24 04          	mov    %eax,0x4(%esp)
 367:	8b 45 08             	mov    0x8(%ebp),%eax
 36a:	89 04 24             	mov    %eax,(%esp)
 36d:	e8 3a ff ff ff       	call   2ac <write>
}
 372:	c9                   	leave  
 373:	c3                   	ret    

00000374 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 374:	55                   	push   %ebp
 375:	89 e5                	mov    %esp,%ebp
 377:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 37a:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 381:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 385:	74 17                	je     39e <printint+0x2a>
 387:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 38b:	79 11                	jns    39e <printint+0x2a>
    neg = 1;
 38d:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 394:	8b 45 0c             	mov    0xc(%ebp),%eax
 397:	f7 d8                	neg    %eax
 399:	89 45 ec             	mov    %eax,-0x14(%ebp)
 39c:	eb 06                	jmp    3a4 <printint+0x30>
  } else {
    x = xx;
 39e:	8b 45 0c             	mov    0xc(%ebp),%eax
 3a1:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 3a4:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 3ab:	8b 4d 10             	mov    0x10(%ebp),%ecx
 3ae:	8b 45 ec             	mov    -0x14(%ebp),%eax
 3b1:	ba 00 00 00 00       	mov    $0x0,%edx
 3b6:	f7 f1                	div    %ecx
 3b8:	89 d0                	mov    %edx,%eax
 3ba:	0f b6 80 d8 12 00 00 	movzbl 0x12d8(%eax),%eax
 3c1:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 3c4:	8b 55 f4             	mov    -0xc(%ebp),%edx
 3c7:	01 ca                	add    %ecx,%edx
 3c9:	88 02                	mov    %al,(%edx)
 3cb:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 3cf:	8b 55 10             	mov    0x10(%ebp),%edx
 3d2:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 3d5:	8b 45 ec             	mov    -0x14(%ebp),%eax
 3d8:	ba 00 00 00 00       	mov    $0x0,%edx
 3dd:	f7 75 d4             	divl   -0x2c(%ebp)
 3e0:	89 45 ec             	mov    %eax,-0x14(%ebp)
 3e3:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 3e7:	75 c2                	jne    3ab <printint+0x37>
  if(neg)
 3e9:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 3ed:	74 2e                	je     41d <printint+0xa9>
    buf[i++] = '-';
 3ef:	8d 55 dc             	lea    -0x24(%ebp),%edx
 3f2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 3f5:	01 d0                	add    %edx,%eax
 3f7:	c6 00 2d             	movb   $0x2d,(%eax)
 3fa:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 3fe:	eb 1d                	jmp    41d <printint+0xa9>
    putc(fd, buf[i]);
 400:	8d 55 dc             	lea    -0x24(%ebp),%edx
 403:	8b 45 f4             	mov    -0xc(%ebp),%eax
 406:	01 d0                	add    %edx,%eax
 408:	0f b6 00             	movzbl (%eax),%eax
 40b:	0f be c0             	movsbl %al,%eax
 40e:	89 44 24 04          	mov    %eax,0x4(%esp)
 412:	8b 45 08             	mov    0x8(%ebp),%eax
 415:	89 04 24             	mov    %eax,(%esp)
 418:	e8 2f ff ff ff       	call   34c <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 41d:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 421:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 425:	79 d9                	jns    400 <printint+0x8c>
    putc(fd, buf[i]);
}
 427:	c9                   	leave  
 428:	c3                   	ret    

00000429 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 429:	55                   	push   %ebp
 42a:	89 e5                	mov    %esp,%ebp
 42c:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 42f:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 436:	8d 45 0c             	lea    0xc(%ebp),%eax
 439:	83 c0 04             	add    $0x4,%eax
 43c:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 43f:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 446:	e9 7d 01 00 00       	jmp    5c8 <printf+0x19f>
    c = fmt[i] & 0xff;
 44b:	8b 55 0c             	mov    0xc(%ebp),%edx
 44e:	8b 45 f0             	mov    -0x10(%ebp),%eax
 451:	01 d0                	add    %edx,%eax
 453:	0f b6 00             	movzbl (%eax),%eax
 456:	0f be c0             	movsbl %al,%eax
 459:	25 ff 00 00 00       	and    $0xff,%eax
 45e:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 461:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 465:	75 2c                	jne    493 <printf+0x6a>
      if(c == '%'){
 467:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 46b:	75 0c                	jne    479 <printf+0x50>
        state = '%';
 46d:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 474:	e9 4b 01 00 00       	jmp    5c4 <printf+0x19b>
      } else {
        putc(fd, c);
 479:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 47c:	0f be c0             	movsbl %al,%eax
 47f:	89 44 24 04          	mov    %eax,0x4(%esp)
 483:	8b 45 08             	mov    0x8(%ebp),%eax
 486:	89 04 24             	mov    %eax,(%esp)
 489:	e8 be fe ff ff       	call   34c <putc>
 48e:	e9 31 01 00 00       	jmp    5c4 <printf+0x19b>
      }
    } else if(state == '%'){
 493:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 497:	0f 85 27 01 00 00    	jne    5c4 <printf+0x19b>
      if(c == 'd'){
 49d:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 4a1:	75 2d                	jne    4d0 <printf+0xa7>
        printint(fd, *ap, 10, 1);
 4a3:	8b 45 e8             	mov    -0x18(%ebp),%eax
 4a6:	8b 00                	mov    (%eax),%eax
 4a8:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 4af:	00 
 4b0:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 4b7:	00 
 4b8:	89 44 24 04          	mov    %eax,0x4(%esp)
 4bc:	8b 45 08             	mov    0x8(%ebp),%eax
 4bf:	89 04 24             	mov    %eax,(%esp)
 4c2:	e8 ad fe ff ff       	call   374 <printint>
        ap++;
 4c7:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 4cb:	e9 ed 00 00 00       	jmp    5bd <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 4d0:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 4d4:	74 06                	je     4dc <printf+0xb3>
 4d6:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 4da:	75 2d                	jne    509 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 4dc:	8b 45 e8             	mov    -0x18(%ebp),%eax
 4df:	8b 00                	mov    (%eax),%eax
 4e1:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 4e8:	00 
 4e9:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 4f0:	00 
 4f1:	89 44 24 04          	mov    %eax,0x4(%esp)
 4f5:	8b 45 08             	mov    0x8(%ebp),%eax
 4f8:	89 04 24             	mov    %eax,(%esp)
 4fb:	e8 74 fe ff ff       	call   374 <printint>
        ap++;
 500:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 504:	e9 b4 00 00 00       	jmp    5bd <printf+0x194>
      } else if(c == 's'){
 509:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 50d:	75 46                	jne    555 <printf+0x12c>
        s = (char*)*ap;
 50f:	8b 45 e8             	mov    -0x18(%ebp),%eax
 512:	8b 00                	mov    (%eax),%eax
 514:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 517:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 51b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 51f:	75 27                	jne    548 <printf+0x11f>
          s = "(null)";
 521:	c7 45 f4 7a 0e 00 00 	movl   $0xe7a,-0xc(%ebp)
        while(*s != 0){
 528:	eb 1e                	jmp    548 <printf+0x11f>
          putc(fd, *s);
 52a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 52d:	0f b6 00             	movzbl (%eax),%eax
 530:	0f be c0             	movsbl %al,%eax
 533:	89 44 24 04          	mov    %eax,0x4(%esp)
 537:	8b 45 08             	mov    0x8(%ebp),%eax
 53a:	89 04 24             	mov    %eax,(%esp)
 53d:	e8 0a fe ff ff       	call   34c <putc>
          s++;
 542:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 546:	eb 01                	jmp    549 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 548:	90                   	nop
 549:	8b 45 f4             	mov    -0xc(%ebp),%eax
 54c:	0f b6 00             	movzbl (%eax),%eax
 54f:	84 c0                	test   %al,%al
 551:	75 d7                	jne    52a <printf+0x101>
 553:	eb 68                	jmp    5bd <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 555:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 559:	75 1d                	jne    578 <printf+0x14f>
        putc(fd, *ap);
 55b:	8b 45 e8             	mov    -0x18(%ebp),%eax
 55e:	8b 00                	mov    (%eax),%eax
 560:	0f be c0             	movsbl %al,%eax
 563:	89 44 24 04          	mov    %eax,0x4(%esp)
 567:	8b 45 08             	mov    0x8(%ebp),%eax
 56a:	89 04 24             	mov    %eax,(%esp)
 56d:	e8 da fd ff ff       	call   34c <putc>
        ap++;
 572:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 576:	eb 45                	jmp    5bd <printf+0x194>
      } else if(c == '%'){
 578:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 57c:	75 17                	jne    595 <printf+0x16c>
        putc(fd, c);
 57e:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 581:	0f be c0             	movsbl %al,%eax
 584:	89 44 24 04          	mov    %eax,0x4(%esp)
 588:	8b 45 08             	mov    0x8(%ebp),%eax
 58b:	89 04 24             	mov    %eax,(%esp)
 58e:	e8 b9 fd ff ff       	call   34c <putc>
 593:	eb 28                	jmp    5bd <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 595:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 59c:	00 
 59d:	8b 45 08             	mov    0x8(%ebp),%eax
 5a0:	89 04 24             	mov    %eax,(%esp)
 5a3:	e8 a4 fd ff ff       	call   34c <putc>
        putc(fd, c);
 5a8:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5ab:	0f be c0             	movsbl %al,%eax
 5ae:	89 44 24 04          	mov    %eax,0x4(%esp)
 5b2:	8b 45 08             	mov    0x8(%ebp),%eax
 5b5:	89 04 24             	mov    %eax,(%esp)
 5b8:	e8 8f fd ff ff       	call   34c <putc>
      }
      state = 0;
 5bd:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 5c4:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 5c8:	8b 55 0c             	mov    0xc(%ebp),%edx
 5cb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 5ce:	01 d0                	add    %edx,%eax
 5d0:	0f b6 00             	movzbl (%eax),%eax
 5d3:	84 c0                	test   %al,%al
 5d5:	0f 85 70 fe ff ff    	jne    44b <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 5db:	c9                   	leave  
 5dc:	c3                   	ret    
 5dd:	66 90                	xchg   %ax,%ax
 5df:	90                   	nop

000005e0 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 5e0:	55                   	push   %ebp
 5e1:	89 e5                	mov    %esp,%ebp
 5e3:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 5e6:	8b 45 08             	mov    0x8(%ebp),%eax
 5e9:	83 e8 08             	sub    $0x8,%eax
 5ec:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 5ef:	a1 08 13 00 00       	mov    0x1308,%eax
 5f4:	89 45 fc             	mov    %eax,-0x4(%ebp)
 5f7:	eb 24                	jmp    61d <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 5f9:	8b 45 fc             	mov    -0x4(%ebp),%eax
 5fc:	8b 00                	mov    (%eax),%eax
 5fe:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 601:	77 12                	ja     615 <free+0x35>
 603:	8b 45 f8             	mov    -0x8(%ebp),%eax
 606:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 609:	77 24                	ja     62f <free+0x4f>
 60b:	8b 45 fc             	mov    -0x4(%ebp),%eax
 60e:	8b 00                	mov    (%eax),%eax
 610:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 613:	77 1a                	ja     62f <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 615:	8b 45 fc             	mov    -0x4(%ebp),%eax
 618:	8b 00                	mov    (%eax),%eax
 61a:	89 45 fc             	mov    %eax,-0x4(%ebp)
 61d:	8b 45 f8             	mov    -0x8(%ebp),%eax
 620:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 623:	76 d4                	jbe    5f9 <free+0x19>
 625:	8b 45 fc             	mov    -0x4(%ebp),%eax
 628:	8b 00                	mov    (%eax),%eax
 62a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 62d:	76 ca                	jbe    5f9 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 62f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 632:	8b 40 04             	mov    0x4(%eax),%eax
 635:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 63c:	8b 45 f8             	mov    -0x8(%ebp),%eax
 63f:	01 c2                	add    %eax,%edx
 641:	8b 45 fc             	mov    -0x4(%ebp),%eax
 644:	8b 00                	mov    (%eax),%eax
 646:	39 c2                	cmp    %eax,%edx
 648:	75 24                	jne    66e <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 64a:	8b 45 f8             	mov    -0x8(%ebp),%eax
 64d:	8b 50 04             	mov    0x4(%eax),%edx
 650:	8b 45 fc             	mov    -0x4(%ebp),%eax
 653:	8b 00                	mov    (%eax),%eax
 655:	8b 40 04             	mov    0x4(%eax),%eax
 658:	01 c2                	add    %eax,%edx
 65a:	8b 45 f8             	mov    -0x8(%ebp),%eax
 65d:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 660:	8b 45 fc             	mov    -0x4(%ebp),%eax
 663:	8b 00                	mov    (%eax),%eax
 665:	8b 10                	mov    (%eax),%edx
 667:	8b 45 f8             	mov    -0x8(%ebp),%eax
 66a:	89 10                	mov    %edx,(%eax)
 66c:	eb 0a                	jmp    678 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 66e:	8b 45 fc             	mov    -0x4(%ebp),%eax
 671:	8b 10                	mov    (%eax),%edx
 673:	8b 45 f8             	mov    -0x8(%ebp),%eax
 676:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 678:	8b 45 fc             	mov    -0x4(%ebp),%eax
 67b:	8b 40 04             	mov    0x4(%eax),%eax
 67e:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 685:	8b 45 fc             	mov    -0x4(%ebp),%eax
 688:	01 d0                	add    %edx,%eax
 68a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 68d:	75 20                	jne    6af <free+0xcf>
    p->s.size += bp->s.size;
 68f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 692:	8b 50 04             	mov    0x4(%eax),%edx
 695:	8b 45 f8             	mov    -0x8(%ebp),%eax
 698:	8b 40 04             	mov    0x4(%eax),%eax
 69b:	01 c2                	add    %eax,%edx
 69d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6a0:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 6a3:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6a6:	8b 10                	mov    (%eax),%edx
 6a8:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ab:	89 10                	mov    %edx,(%eax)
 6ad:	eb 08                	jmp    6b7 <free+0xd7>
  } else
    p->s.ptr = bp;
 6af:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6b2:	8b 55 f8             	mov    -0x8(%ebp),%edx
 6b5:	89 10                	mov    %edx,(%eax)
  freep = p;
 6b7:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ba:	a3 08 13 00 00       	mov    %eax,0x1308
}
 6bf:	c9                   	leave  
 6c0:	c3                   	ret    

000006c1 <morecore>:

static Header*
morecore(uint nu)
{
 6c1:	55                   	push   %ebp
 6c2:	89 e5                	mov    %esp,%ebp
 6c4:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 6c7:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 6ce:	77 07                	ja     6d7 <morecore+0x16>
    nu = 4096;
 6d0:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 6d7:	8b 45 08             	mov    0x8(%ebp),%eax
 6da:	c1 e0 03             	shl    $0x3,%eax
 6dd:	89 04 24             	mov    %eax,(%esp)
 6e0:	e8 2f fc ff ff       	call   314 <sbrk>
 6e5:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 6e8:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 6ec:	75 07                	jne    6f5 <morecore+0x34>
    return 0;
 6ee:	b8 00 00 00 00       	mov    $0x0,%eax
 6f3:	eb 22                	jmp    717 <morecore+0x56>
  hp = (Header*)p;
 6f5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 6f8:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 6fb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 6fe:	8b 55 08             	mov    0x8(%ebp),%edx
 701:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 704:	8b 45 f0             	mov    -0x10(%ebp),%eax
 707:	83 c0 08             	add    $0x8,%eax
 70a:	89 04 24             	mov    %eax,(%esp)
 70d:	e8 ce fe ff ff       	call   5e0 <free>
  return freep;
 712:	a1 08 13 00 00       	mov    0x1308,%eax
}
 717:	c9                   	leave  
 718:	c3                   	ret    

00000719 <malloc>:

void*
malloc(uint nbytes)
{
 719:	55                   	push   %ebp
 71a:	89 e5                	mov    %esp,%ebp
 71c:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 71f:	8b 45 08             	mov    0x8(%ebp),%eax
 722:	83 c0 07             	add    $0x7,%eax
 725:	c1 e8 03             	shr    $0x3,%eax
 728:	83 c0 01             	add    $0x1,%eax
 72b:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 72e:	a1 08 13 00 00       	mov    0x1308,%eax
 733:	89 45 f0             	mov    %eax,-0x10(%ebp)
 736:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 73a:	75 23                	jne    75f <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 73c:	c7 45 f0 00 13 00 00 	movl   $0x1300,-0x10(%ebp)
 743:	8b 45 f0             	mov    -0x10(%ebp),%eax
 746:	a3 08 13 00 00       	mov    %eax,0x1308
 74b:	a1 08 13 00 00       	mov    0x1308,%eax
 750:	a3 00 13 00 00       	mov    %eax,0x1300
    base.s.size = 0;
 755:	c7 05 04 13 00 00 00 	movl   $0x0,0x1304
 75c:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 75f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 762:	8b 00                	mov    (%eax),%eax
 764:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 767:	8b 45 f4             	mov    -0xc(%ebp),%eax
 76a:	8b 40 04             	mov    0x4(%eax),%eax
 76d:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 770:	72 4d                	jb     7bf <malloc+0xa6>
      if(p->s.size == nunits)
 772:	8b 45 f4             	mov    -0xc(%ebp),%eax
 775:	8b 40 04             	mov    0x4(%eax),%eax
 778:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 77b:	75 0c                	jne    789 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 77d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 780:	8b 10                	mov    (%eax),%edx
 782:	8b 45 f0             	mov    -0x10(%ebp),%eax
 785:	89 10                	mov    %edx,(%eax)
 787:	eb 26                	jmp    7af <malloc+0x96>
      else {
        p->s.size -= nunits;
 789:	8b 45 f4             	mov    -0xc(%ebp),%eax
 78c:	8b 40 04             	mov    0x4(%eax),%eax
 78f:	89 c2                	mov    %eax,%edx
 791:	2b 55 ec             	sub    -0x14(%ebp),%edx
 794:	8b 45 f4             	mov    -0xc(%ebp),%eax
 797:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 79a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 79d:	8b 40 04             	mov    0x4(%eax),%eax
 7a0:	c1 e0 03             	shl    $0x3,%eax
 7a3:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 7a6:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7a9:	8b 55 ec             	mov    -0x14(%ebp),%edx
 7ac:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 7af:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7b2:	a3 08 13 00 00       	mov    %eax,0x1308
      return (void*)(p + 1);
 7b7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ba:	83 c0 08             	add    $0x8,%eax
 7bd:	eb 38                	jmp    7f7 <malloc+0xde>
    }
    if(p == freep)
 7bf:	a1 08 13 00 00       	mov    0x1308,%eax
 7c4:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 7c7:	75 1b                	jne    7e4 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 7c9:	8b 45 ec             	mov    -0x14(%ebp),%eax
 7cc:	89 04 24             	mov    %eax,(%esp)
 7cf:	e8 ed fe ff ff       	call   6c1 <morecore>
 7d4:	89 45 f4             	mov    %eax,-0xc(%ebp)
 7d7:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 7db:	75 07                	jne    7e4 <malloc+0xcb>
        return 0;
 7dd:	b8 00 00 00 00       	mov    $0x0,%eax
 7e2:	eb 13                	jmp    7f7 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 7e4:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e7:	89 45 f0             	mov    %eax,-0x10(%ebp)
 7ea:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ed:	8b 00                	mov    (%eax),%eax
 7ef:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 7f2:	e9 70 ff ff ff       	jmp    767 <malloc+0x4e>
}
 7f7:	c9                   	leave  
 7f8:	c3                   	ret    
 7f9:	66 90                	xchg   %ax,%ax
 7fb:	90                   	nop

000007fc <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 7fc:	55                   	push   %ebp
 7fd:	89 e5                	mov    %esp,%ebp
 7ff:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 802:	c7 05 20 13 00 00 00 	movl   $0x0,0x1320
 809:	00 00 00 
	STORE_ESP(ttable[0].esp);
 80c:	89 e0                	mov    %esp,%eax
 80e:	a3 24 13 00 00       	mov    %eax,0x1324
	STORE_EBP(ttable[0].ebp);
 813:	89 e8                	mov    %ebp,%eax
 815:	a3 28 13 00 00       	mov    %eax,0x1328
	ttable[0].state = T_RUNNING;
 81a:	c7 05 30 13 00 00 01 	movl   $0x1,0x1330
 821:	00 00 00 
	ttable[0].wait_num = 0;
 824:	c7 05 34 14 00 00 00 	movl   $0x0,0x1434
 82b:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 82e:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 835:	eb 2c                	jmp    863 <uthread_init+0x67>
	{
		ttable[i].tid = i;
 837:	8b 45 f4             	mov    -0xc(%ebp),%eax
 83a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 840:	8d 90 20 13 00 00    	lea    0x1320(%eax),%edx
 846:	8b 45 f4             	mov    -0xc(%ebp),%eax
 849:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 84b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 84e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 854:	05 30 13 00 00       	add    $0x1330,%eax
 859:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 85f:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 863:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 867:	7e ce                	jle    837 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 869:	c7 44 24 04 ef 0a 00 	movl   $0xaef,0x4(%esp)
 870:	00 
 871:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 878:	e8 af fa ff ff       	call   32c <signal>
	alarm(THREAD_QUANTA);
 87d:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 884:	e8 b3 fa ff ff       	call   33c <alarm>
}
 889:	c9                   	leave  
 88a:	c3                   	ret    

0000088b <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 88b:	55                   	push   %ebp
 88c:	89 e5                	mov    %esp,%ebp
 88e:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 891:	60                   	pusha  
	ticks = getTicks();
 892:	e8 ad fa ff ff       	call   344 <getTicks>
 897:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 89a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 8a1:	e8 96 fa ff ff       	call   33c <alarm>
	asm("popa");
 8a6:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 8a7:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 8ae:	e9 02 01 00 00       	jmp    9b5 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 8b3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8b6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 8bc:	05 30 13 00 00       	add    $0x1330,%eax
 8c1:	8b 00                	mov    (%eax),%eax
 8c3:	85 c0                	test   %eax,%eax
 8c5:	0f 85 e6 00 00 00    	jne    9b1 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 8cb:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 8d2:	e8 42 fe ff ff       	call   719 <malloc>
 8d7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 8da:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 8e0:	81 c2 20 13 00 00    	add    $0x1320,%edx
 8e6:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 8e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8ec:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 8f2:	05 20 13 00 00       	add    $0x1320,%eax
 8f7:	8b 40 0c             	mov    0xc(%eax),%eax
 8fa:	05 00 10 00 00       	add    $0x1000,%eax
 8ff:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 901:	8b 45 0c             	mov    0xc(%ebp),%eax
 904:	89 c7                	mov    %eax,%edi
 906:	57                   	push   %edi
			PUSH(uthread_exit);
 907:	b8 75 0b 00 00       	mov    $0xb75,%eax
 90c:	89 c7                	mov    %eax,%edi
 90e:	57                   	push   %edi
			PUSH(start_func);
 90f:	8b 45 08             	mov    0x8(%ebp),%eax
 912:	89 c7                	mov    %eax,%edi
 914:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 915:	b8 00 00 00 00       	mov    $0x0,%eax
 91a:	89 c7                	mov    %eax,%edi
 91c:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 91d:	89 e0                	mov    %esp,%eax
 91f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 922:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 928:	81 c2 20 13 00 00    	add    $0x1320,%edx
 92e:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 931:	8b 45 f4             	mov    -0xc(%ebp),%eax
 934:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 93a:	05 20 13 00 00       	add    $0x1320,%eax
 93f:	8b 40 08             	mov    0x8(%eax),%eax
 942:	8b 55 f4             	mov    -0xc(%ebp),%edx
 945:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 94b:	81 c2 20 13 00 00    	add    $0x1320,%edx
 951:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 954:	a1 0c 13 00 00       	mov    0x130c,%eax
 959:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 95f:	05 20 13 00 00       	add    $0x1320,%eax
 964:	8b 40 04             	mov    0x4(%eax),%eax
 967:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 969:	8b 45 f4             	mov    -0xc(%ebp),%eax
 96c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 972:	05 30 13 00 00       	add    $0x1330,%eax
 977:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 97d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 980:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 986:	05 30 14 00 00       	add    $0x1430,%eax
 98b:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 992:	60                   	pusha  
			alarm(ticks);
 993:	8b 45 f0             	mov    -0x10(%ebp),%eax
 996:	89 04 24             	mov    %eax,(%esp)
 999:	e8 9e f9 ff ff       	call   33c <alarm>
			asm("popa");
 99e:	61                   	popa   
			return ttable[i].tid;
 99f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9a2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9a8:	05 20 13 00 00       	add    $0x1320,%eax
 9ad:	8b 00                	mov    (%eax),%eax
 9af:	eb 1e                	jmp    9cf <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 9b1:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 9b5:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 9b9:	0f 8e f4 fe ff ff    	jle    8b3 <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 9bf:	8b 45 f0             	mov    -0x10(%ebp),%eax
 9c2:	89 04 24             	mov    %eax,(%esp)
 9c5:	e8 72 f9 ff ff       	call   33c <alarm>
	//failed - no free thread to use
	return -1;
 9ca:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 9cf:	c9                   	leave  
 9d0:	c3                   	ret    

000009d1 <safe_exit>:

// task 2.4


void safe_exit()
{
 9d1:	55                   	push   %ebp
 9d2:	89 e5                	mov    %esp,%ebp
 9d4:	83 ec 28             	sub    $0x28,%esp
 9d7:	eb 01                	jmp    9da <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 9d9:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 9da:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 9e1:	eb 25                	jmp    a08 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 9e3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9e6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ec:	05 30 13 00 00       	add    $0x1330,%eax
 9f1:	8b 00                	mov    (%eax),%eax
 9f3:	85 c0                	test   %eax,%eax
 9f5:	74 0d                	je     a04 <safe_exit+0x33>
				uthread_join(tid);
 9f7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9fa:	89 04 24             	mov    %eax,(%esp)
 9fd:	e8 1d 02 00 00       	call   c1f <uthread_join>
				break;
 a02:	eb 0a                	jmp    a0e <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a04:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a08:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a0c:	7e d5                	jle    9e3 <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 a0e:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 a12:	75 c5                	jne    9d9 <safe_exit+0x8>
			exit();
 a14:	e8 73 f8 ff ff       	call   28c <exit>

00000a19 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 a19:	55                   	push   %ebp
 a1a:	89 e5                	mov    %esp,%ebp
 a1c:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 a1f:	a1 0c 13 00 00       	mov    0x130c,%eax
 a24:	8d 50 01             	lea    0x1(%eax),%edx
 a27:	89 d0                	mov    %edx,%eax
 a29:	c1 f8 1f             	sar    $0x1f,%eax
 a2c:	c1 e8 1a             	shr    $0x1a,%eax
 a2f:	01 c2                	add    %eax,%edx
 a31:	83 e2 3f             	and    $0x3f,%edx
 a34:	89 d1                	mov    %edx,%ecx
 a36:	29 c1                	sub    %eax,%ecx
 a38:	89 c8                	mov    %ecx,%eax
 a3a:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 a3d:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 a44:	eb 20                	jmp    a66 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 a46:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a49:	8d 50 01             	lea    0x1(%eax),%edx
 a4c:	89 d0                	mov    %edx,%eax
 a4e:	c1 f8 1f             	sar    $0x1f,%eax
 a51:	c1 e8 1a             	shr    $0x1a,%eax
 a54:	01 c2                	add    %eax,%edx
 a56:	83 e2 3f             	and    $0x3f,%edx
 a59:	89 d1                	mov    %edx,%ecx
 a5b:	29 c1                	sub    %eax,%ecx
 a5d:	89 c8                	mov    %ecx,%eax
 a5f:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 a62:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a66:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a69:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a6f:	05 30 13 00 00       	add    $0x1330,%eax
 a74:	8b 00                	mov    (%eax),%eax
 a76:	83 f8 02             	cmp    $0x2,%eax
 a79:	74 06                	je     a81 <uthread_switch+0x68>
 a7b:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a7f:	7e c5                	jle    a46 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 a81:	8b 15 0c 13 00 00    	mov    0x130c,%edx
 a87:	89 e0                	mov    %esp,%eax
 a89:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 a8f:	81 c2 20 13 00 00    	add    $0x1320,%edx
 a95:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 a98:	8b 15 0c 13 00 00    	mov    0x130c,%edx
 a9e:	89 e8                	mov    %ebp,%eax
 aa0:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 aa6:	81 c2 20 13 00 00    	add    $0x1320,%edx
 aac:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 aaf:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ab2:	a3 0c 13 00 00       	mov    %eax,0x130c
	LOAD_EBP(ttable[c_thread].ebp);
 ab7:	a1 0c 13 00 00       	mov    0x130c,%eax
 abc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ac2:	05 20 13 00 00       	add    $0x1320,%eax
 ac7:	8b 40 08             	mov    0x8(%eax),%eax
 aca:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 acc:	a1 0c 13 00 00       	mov    0x130c,%eax
 ad1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ad7:	05 20 13 00 00       	add    $0x1320,%eax
 adc:	8b 40 04             	mov    0x4(%eax),%eax
 adf:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 ae1:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 ae8:	e8 4f f8 ff ff       	call   33c <alarm>
}
 aed:	c9                   	leave  
 aee:	c3                   	ret    

00000aef <uthread_yield>:

void uthread_yield()
{
 aef:	55                   	push   %ebp
 af0:	89 e5                	mov    %esp,%ebp
 af2:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 af5:	60                   	pusha  
	alarm(0);
 af6:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 afd:	e8 3a f8 ff ff       	call   33c <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 b02:	a1 0c 13 00 00       	mov    0x130c,%eax
 b07:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b0d:	05 30 13 00 00       	add    $0x1330,%eax
 b12:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 b18:	e8 fc fe ff ff       	call   a19 <uthread_switch>
	asm("popa");
 b1d:	61                   	popa   
}
 b1e:	c9                   	leave  
 b1f:	c3                   	ret    

00000b20 <uthread_awake>:

// task 2.5

void uthread_awake()
{
 b20:	55                   	push   %ebp
 b21:	89 e5                	mov    %esp,%ebp
 b23:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b26:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 b2d:	eb 2c                	jmp    b5b <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 b2f:	a1 0c 13 00 00       	mov    0x130c,%eax
 b34:	6b d0 46             	imul   $0x46,%eax,%edx
 b37:	8b 45 fc             	mov    -0x4(%ebp),%eax
 b3a:	01 d0                	add    %edx,%eax
 b3c:	83 c0 04             	add    $0x4,%eax
 b3f:	8b 04 85 24 13 00 00 	mov    0x1324(,%eax,4),%eax
 b46:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b4c:	05 30 13 00 00       	add    $0x1330,%eax
 b51:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b57:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 b5b:	a1 0c 13 00 00       	mov    0x130c,%eax
 b60:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b66:	05 30 14 00 00       	add    $0x1430,%eax
 b6b:	8b 40 04             	mov    0x4(%eax),%eax
 b6e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 b71:	7f bc                	jg     b2f <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 b73:	c9                   	leave  
 b74:	c3                   	ret    

00000b75 <uthread_exit>:

void uthread_exit()
{
 b75:	55                   	push   %ebp
 b76:	89 e5                	mov    %esp,%ebp
 b78:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 b7b:	60                   	pusha  
	alarm(0);
 b7c:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 b83:	e8 b4 f7 ff ff       	call   33c <alarm>
	asm("popa");
 b88:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 b89:	a1 0c 13 00 00       	mov    0x130c,%eax
 b8e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b94:	05 30 13 00 00       	add    $0x1330,%eax
 b99:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 b9f:	a1 0c 13 00 00       	mov    0x130c,%eax
 ba4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 baa:	05 20 13 00 00       	add    $0x1320,%eax
 baf:	8b 00                	mov    (%eax),%eax
 bb1:	85 c0                	test   %eax,%eax
 bb3:	74 1d                	je     bd2 <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 bb5:	a1 0c 13 00 00       	mov    0x130c,%eax
 bba:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bc0:	05 20 13 00 00       	add    $0x1320,%eax
 bc5:	8b 40 0c             	mov    0xc(%eax),%eax
 bc8:	89 04 24             	mov    %eax,(%esp)
 bcb:	e8 10 fa ff ff       	call   5e0 <free>
 bd0:	eb 05                	jmp    bd7 <uthread_exit+0x62>
	else
		safe_exit();
 bd2:	e8 fa fd ff ff       	call   9d1 <safe_exit>
	uthread_awake();
 bd7:	e8 44 ff ff ff       	call   b20 <uthread_awake>
	uthread_switch();
 bdc:	e8 38 fe ff ff       	call   a19 <uthread_switch>
	asm("popa");
 be1:	61                   	popa   
}
 be2:	c9                   	leave  
 be3:	c3                   	ret    

00000be4 <uthread_self>:

// task 2.6

int uthread_self()
{
 be4:	55                   	push   %ebp
 be5:	89 e5                	mov    %esp,%ebp
	return c_thread;
 be7:	a1 0c 13 00 00       	mov    0x130c,%eax
}
 bec:	5d                   	pop    %ebp
 bed:	c3                   	ret    

00000bee <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 bee:	55                   	push   %ebp
 bef:	89 e5                	mov    %esp,%ebp
 bf1:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 bf4:	60                   	pusha  
	alarm(0);
 bf5:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bfc:	e8 3b f7 ff ff       	call   33c <alarm>
	ttable[c_thread].state = T_SLEEPING;
 c01:	a1 0c 13 00 00       	mov    0x130c,%eax
 c06:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c0c:	05 30 13 00 00       	add    $0x1330,%eax
 c11:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 c17:	e8 fd fd ff ff       	call   a19 <uthread_switch>
	asm("popa");
 c1c:	61                   	popa   
}
 c1d:	c9                   	leave  
 c1e:	c3                   	ret    

00000c1f <uthread_join>:

int uthread_join(int tid)
{
 c1f:	55                   	push   %ebp
 c20:	89 e5                	mov    %esp,%ebp
 c22:	53                   	push   %ebx
 c23:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 c26:	60                   	pusha  
	ticks = getTicks();
 c27:	e8 18 f7 ff ff       	call   344 <getTicks>
 c2c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 c2f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c36:	e8 01 f7 ff ff       	call   33c <alarm>
	asm("popa");
 c3b:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 c3c:	8b 45 08             	mov    0x8(%ebp),%eax
 c3f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c45:	05 30 13 00 00       	add    $0x1330,%eax
 c4a:	8b 00                	mov    (%eax),%eax
 c4c:	85 c0                	test   %eax,%eax
 c4e:	74 5e                	je     cae <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 c50:	8b 45 08             	mov    0x8(%ebp),%eax
 c53:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c59:	05 10 01 00 00       	add    $0x110,%eax
 c5e:	05 20 13 00 00       	add    $0x1320,%eax
 c63:	8d 48 04             	lea    0x4(%eax),%ecx
 c66:	8b 45 08             	mov    0x8(%ebp),%eax
 c69:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c6f:	05 30 14 00 00       	add    $0x1430,%eax
 c74:	8b 40 04             	mov    0x4(%eax),%eax
 c77:	8b 15 0c 13 00 00    	mov    0x130c,%edx
 c7d:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 c83:	81 c2 20 13 00 00    	add    $0x1320,%edx
 c89:	8b 12                	mov    (%edx),%edx
 c8b:	8b 5d 08             	mov    0x8(%ebp),%ebx
 c8e:	6b db 46             	imul   $0x46,%ebx,%ebx
 c91:	01 c3                	add    %eax,%ebx
 c93:	83 c3 04             	add    $0x4,%ebx
 c96:	89 14 9d 24 13 00 00 	mov    %edx,0x1324(,%ebx,4)
 c9d:	83 c0 01             	add    $0x1,%eax
 ca0:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 ca2:	e8 47 ff ff ff       	call   bee <uthread_sleep>
		return 0;
 ca7:	b8 00 00 00 00       	mov    $0x0,%eax
 cac:	eb 12                	jmp    cc0 <uthread_join+0xa1>
	}
	asm("pusha");
 cae:	60                   	pusha  
	alarm(ticks);
 caf:	8b 45 f4             	mov    -0xc(%ebp),%eax
 cb2:	89 04 24             	mov    %eax,(%esp)
 cb5:	e8 82 f6 ff ff       	call   33c <alarm>
	asm("popa");
 cba:	61                   	popa   
	return -1;
 cbb:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 cc0:	83 c4 24             	add    $0x24,%esp
 cc3:	5b                   	pop    %ebx
 cc4:	5d                   	pop    %ebp
 cc5:	c3                   	ret    

00000cc6 <queue_init>:

void queue_init(struct tqueue *q)
{
 cc6:	55                   	push   %ebp
 cc7:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 cc9:	8b 45 08             	mov    0x8(%ebp),%eax
 ccc:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 cd3:	00 00 00 
	q->tail = 0;
 cd6:	8b 45 08             	mov    0x8(%ebp),%eax
 cd9:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 ce0:	00 00 00 
}
 ce3:	5d                   	pop    %ebp
 ce4:	c3                   	ret    

00000ce5 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 ce5:	55                   	push   %ebp
 ce6:	89 e5                	mov    %esp,%ebp
 ce8:	57                   	push   %edi
 ce9:	56                   	push   %esi
 cea:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 ceb:	8b 45 08             	mov    0x8(%ebp),%eax
 cee:	8b 00                	mov    (%eax),%eax
 cf0:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 cf6:	8b 45 08             	mov    0x8(%ebp),%eax
 cf9:	8b 00                	mov    (%eax),%eax
 cfb:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 d01:	39 c2                	cmp    %eax,%edx
 d03:	75 07                	jne    d0c <dequeue+0x27>
		return 0;
 d05:	b9 00 00 00 00       	mov    $0x0,%ecx
 d0a:	eb 31                	jmp    d3d <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 d0c:	8b 45 08             	mov    0x8(%ebp),%eax
 d0f:	8b 18                	mov    (%eax),%ebx
 d11:	8b 45 08             	mov    0x8(%ebp),%eax
 d14:	8b 10                	mov    (%eax),%edx
 d16:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 d1c:	89 c1                	mov    %eax,%ecx
 d1e:	c1 f9 1f             	sar    $0x1f,%ecx
 d21:	c1 e9 1a             	shr    $0x1a,%ecx
 d24:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d27:	83 e6 3f             	and    $0x3f,%esi
 d2a:	89 f7                	mov    %esi,%edi
 d2c:	29 cf                	sub    %ecx,%edi
 d2e:	89 f9                	mov    %edi,%ecx
 d30:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 d33:	83 c0 01             	add    $0x1,%eax
 d36:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 d3c:	90                   	nop
 d3d:	89 c8                	mov    %ecx,%eax
}
 d3f:	5b                   	pop    %ebx
 d40:	5e                   	pop    %esi
 d41:	5f                   	pop    %edi
 d42:	5d                   	pop    %ebp
 d43:	c3                   	ret    

00000d44 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 d44:	55                   	push   %ebp
 d45:	89 e5                	mov    %esp,%ebp
 d47:	57                   	push   %edi
 d48:	56                   	push   %esi
 d49:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 d4a:	8b 45 08             	mov    0x8(%ebp),%eax
 d4d:	8b 18                	mov    (%eax),%ebx
 d4f:	8b 45 08             	mov    0x8(%ebp),%eax
 d52:	8b 10                	mov    (%eax),%edx
 d54:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 d5a:	89 c1                	mov    %eax,%ecx
 d5c:	c1 f9 1f             	sar    $0x1f,%ecx
 d5f:	c1 e9 1a             	shr    $0x1a,%ecx
 d62:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d65:	83 e6 3f             	and    $0x3f,%esi
 d68:	89 f7                	mov    %esi,%edi
 d6a:	29 cf                	sub    %ecx,%edi
 d6c:	89 f9                	mov    %edi,%ecx
 d6e:	8b 35 0c 13 00 00    	mov    0x130c,%esi
 d74:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 d7a:	81 c6 20 13 00 00    	add    $0x1320,%esi
 d80:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 d83:	83 c0 01             	add    $0x1,%eax
 d86:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 d8c:	5b                   	pop    %ebx
 d8d:	5e                   	pop    %esi
 d8e:	5f                   	pop    %edi
 d8f:	5d                   	pop    %ebp
 d90:	c3                   	ret    

00000d91 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 d91:	55                   	push   %ebp
 d92:	89 e5                	mov    %esp,%ebp
 d94:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 d97:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 d9e:	e8 76 f9 ff ff       	call   719 <malloc>
 da3:	8b 55 08             	mov    0x8(%ebp),%edx
 da6:	89 02                	mov    %eax,(%edx)
	if (!value)
 da8:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 dac:	75 0c                	jne    dba <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 dae:	8b 45 08             	mov    0x8(%ebp),%eax
 db1:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 db8:	eb 0a                	jmp    dc4 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 dba:	8b 45 08             	mov    0x8(%ebp),%eax
 dbd:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 dc4:	c9                   	leave  
 dc5:	c3                   	ret    

00000dc6 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 dc6:	55                   	push   %ebp
 dc7:	89 e5                	mov    %esp,%ebp
 dc9:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 dcc:	60                   	pusha  
	ticks = getTicks();
 dcd:	e8 72 f5 ff ff       	call   344 <getTicks>
 dd2:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 dd5:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ddc:	e8 5b f5 ff ff       	call   33c <alarm>
	asm("popa");
 de1:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 de2:	8b 45 08             	mov    0x8(%ebp),%eax
 de5:	8b 40 04             	mov    0x4(%eax),%eax
 de8:	83 f8 01             	cmp    $0x1,%eax
 deb:	75 1c                	jne    e09 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 ded:	8b 45 08             	mov    0x8(%ebp),%eax
 df0:	89 04 24             	mov    %eax,(%esp)
 df3:	e8 4c ff ff ff       	call   d44 <enqueue>
		uthread_sleep();
 df8:	e8 f1 fd ff ff       	call   bee <uthread_sleep>
		alarm(0);
 dfd:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e04:	e8 33 f5 ff ff       	call   33c <alarm>
	}
	semaphore->state = S_LOCKED;
 e09:	8b 45 08             	mov    0x8(%ebp),%eax
 e0c:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 e13:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e16:	89 04 24             	mov    %eax,(%esp)
 e19:	e8 1e f5 ff ff       	call   33c <alarm>

}
 e1e:	c9                   	leave  
 e1f:	c3                   	ret    

00000e20 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 e20:	55                   	push   %ebp
 e21:	89 e5                	mov    %esp,%ebp
 e23:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 e26:	60                   	pusha  
	ticks = getTicks();
 e27:	e8 18 f5 ff ff       	call   344 <getTicks>
 e2c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e2f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e36:	e8 01 f5 ff ff       	call   33c <alarm>
	asm("popa");
 e3b:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 e3c:	8b 45 08             	mov    0x8(%ebp),%eax
 e3f:	89 04 24             	mov    %eax,(%esp)
 e42:	e8 9e fe ff ff       	call   ce5 <dequeue>
 e47:	89 45 f0             	mov    %eax,-0x10(%ebp)
 e4a:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 e4e:	75 19                	jne    e69 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 e50:	8b 45 08             	mov    0x8(%ebp),%eax
 e53:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 e5a:	60                   	pusha  
		alarm(ticks);
 e5b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e5e:	89 04 24             	mov    %eax,(%esp)
 e61:	e8 d6 f4 ff ff       	call   33c <alarm>
		asm("popa");
 e66:	61                   	popa   
 e67:	eb 0f                	jmp    e78 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 e69:	8b 45 f0             	mov    -0x10(%ebp),%eax
 e6c:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 e73:	e8 77 fc ff ff       	call   aef <uthread_yield>
	}
}
 e78:	c9                   	leave  
 e79:	c3                   	ret    
